#include<bits/stdc++.h>
using namespace std;
int t,n,m,len,vm,d,v,a,p,l[100010],r[100010],tot,cnt;
bool rk[100010];
bitset<100010> b[100010],k,h;
int Min(int xx,int yy) {
    return xx < yy? xx: yy;
}
void dfs(int dep,int cntt) {
    if (dep > m) {
        if (k == h) cnt = Min(cnt,cntt);
        return;
    }
    dfs(dep + 1,cntt);
    bitset<100010> tmp = k;
    k |= b[dep];
    dfs(dep + 1,cntt + 1);
    k = tmp;
    return;
}
int main() {
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&t);
    for (int kkk = 1;kkk <= t;kkk ++) {
        memset(rk,false,sizeof(rk));
        tot = 0;
        cnt = INT_MAX;
        h = 0;
        k = 0;
        for (int i = 1;i <= m;i ++)
            b[i] = 0;
        //memset(l,0,sizeof(l));
        //memset(r,0,sizeof(r));
        scanf("%d%d%d%d",&n,&m,&len,&vm);
        for (int i = 1;i <= n;i ++) {
            scanf("%d%d%d",&d,&v,&a);
            if (a == 0) {
                if (v > vm) {
                    l[i] = d;
                    r[i] = len;
                } else {
                    l[i] = len + 1;
                    r[i] = 0;
                }
            } else if (a > 0) {
                if (v > vm) {
                    l[i] = d;
                    r[i] = len;
                } else {
                    l[i] = d + floor(((long double)(vm * vm - v * v)) / (2 * a)) + 1;
                    r[i] = len;
                }
            } else if (a < 0) {
                if (v > vm) {
                    l[i] = d;
                    r[i] = d + ceil(((long double)(vm * vm - v * v)) / (2 * a)) - 1;
                } else {
                    l[i] = len + 1;
                    r[i] = 0;
                }
            }
        }
        //for (int i = 1;i <= n;i ++)
            //printf("l[%d]=%d r[%d]=%d\n",i,l[i],i,r[i]);
        for (int kk = 1;kk <= m;kk ++) {
            scanf("%d",&p);
            for (int i = 1;i <= n;i ++)
                if (l[i] <= r[i] && (p >= l[i] && p <= r[i])) {
                    rk[i] = true;
                    b[kk] |= (1 << (i - 1));
                    h |= (1 << (i - 1));
                    //cout << "b[" << kk << "]:"<< i << " l[" << i << "]=" << l[i] << " r[" << i << "]=" << r[i] << " p=" << p << endl;
                }
        }
        for (int i = 1;i <= n;i ++)
            if (rk[i]) ++ tot;
        //cout << "h=" << h.to_string() << endl;
        //for (int i = 1;i <= m;i ++)
            //cout << b[i].to_string() << endl;
        dfs(1,0);
        printf("%d %d\n",tot,m - cnt);
    }
    return 0;
}
